package com.zhika.zishi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhika.zishi.R;
import com.zhika.zishi.beans.EditStrategyGridBean;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/17.
 */
public class EditStrategyGridAdapter extends BaseAdapter {

    private Context context;

    private ArrayList<EditStrategyGridBean> editStrategyList;

    public EditStrategyGridAdapter(Context context,ArrayList<EditStrategyGridBean> editStrategyList){
        this.context = context;
        this.editStrategyList = editStrategyList;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public int getCount() {
        return editStrategyList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_of_edit_strategy,null);
            holder = new ViewHolder();
            holder.pictureImageView = (ImageView) view.findViewById(R.id.item_of_edit_strategy_image_view);
            holder.contentText = (TextView) view.findViewById(R.id.item_of_edit_strategy_content_text);
            holder.pageNumText = (TextView) view.findViewById(R.id.item_of_edit_strategy_page_num_text);

            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
            resetViewHolder(holder);
        }

        EditStrategyGridBean bean = editStrategyList.get(position);

        holder.pictureImageView.setImageResource(R.drawable.test_1);

        holder.contentText.setText(bean.getContentStr());

        holder.pageNumText.setText(bean.getPageNumStr());

        return view;
    }

    private void resetViewHolder(ViewHolder holder){

        holder.pictureImageView.setImageBitmap(null);

        holder.contentText.setText(null);

        holder.pageNumText.setText(null);
    }
    private class ViewHolder{
        private ImageView pictureImageView;

        private TextView contentText;

        private TextView pageNumText;

    }
}
